#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         chAutoMic

 Script Function:
	Change microphone settings for auto test.

#ce ----------------------------------------------------------------------------

#NoTrayIcon
#include <GuiListView.au3>
#include <GuiComboBox.au3>

$TitleRec="Sound"
$TitlePro="Stereo Mix Properties"
$MICPro="Microphone Properties"

If StringRight(@OSLang, 2) = 04 Then
  $TitleRec="声音"
  $TitlePro="立体声混音 属性"
  $MICPro="麦克风 属性"
EndIf

If $cmdline[0] <> 1 Then
   MsgBox(64, "Usage", "chAutoMIC.exe [-AUTO] | [-Normal] | [-Noise] | [-NoiseAndEcho] | [-NoiseAndEchoNoBeam]"&Chr(10)&Chr(13)& _
			   "-AUTO                 Automatic Test setting"&Chr(10)&Chr(13)& _
			   "-Normal              Normal test setting"&Chr(10)&Chr(13)& _
			   "-Noise                  Enable Noise setting"&Chr(10)&Chr(13)& _
			   "-NoiseAndEcho  Enable Noise and Echo setting")
   Exit(1)
EndIf

Switch ($cmdline[1])
   Case "-AUTO"
	  $id=1
   Case "-Normal"
	  $id=2
   Case "-Noise"
	  $id=3
   Case "-NoiseAndEcho"
	  $id=4
   Case "-NoiseAndEchoNoBeam"
	  $id=5
   Case Else
	  MsgBox(48, "Error", "parameter is wrong")
	  MsgBox(64, "Usage", "chAutoMac.exe [-AUTO] | [-Normal]"&Chr(10)&Chr(13)&"AUTO           Automatic Test setting"&Chr(10)&Chr(13)&"Normal        Normal test setting")
	  Exit(1)
EndSwitch


run("C:\WINDOWS\SYSTEM32\rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,recording", "C:\WINDOWS\SYSTEM32\")

WinWait($TitleRec)
ConsoleWrite(ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","GetItemCount"))
ConsoleWrite("Run..."&$cmdline[1])
If ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","GetItemCount") <> 2 Then
   MsgBox(48, "Error", "Microphone is missing!!!")
   ControlClick($TitleRec,"","[CLASS:Button; INSTANCE:4]")
   Exit (1)
EndIf

switch ($id)
   Case 1:
	  ;setting for Stereo Mix
	  ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","Select",1)
	  Sleep(600)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:3]")
	  Sleep(600)
	  $handle=ControlGetHandle($TitlePro, '', "[CLASS:ComboBox; INSTANCE:1]")
	  Sleep(600)
	  _GUICtrlComboBox_SetCurSel($handle, 0);
	  ControlClick($TitlePro,"","[CLASS:Button; INSTANCE:6]")
	  Sleep(600)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:2]")
   Case 2:
	  ;setting for Microphone----normal
	  ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","Select",0)
	  Sleep(600)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:2]")
	  ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","Select",1)
	  Sleep(600)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:3]")
	  Sleep(600)
	  $handle=ControlGetHandle($TitlePro, '', "[CLASS:ComboBox; INSTANCE:1]")
	  Sleep(600)
	  _GUICtrlComboBox_SetCurSel($handle, 1);
	  Sleep(600)
	  ControlClick($TitlePro,"","[CLASS:Button; INSTANCE:6]")
   Case 3:
	  ;setting for Microphone----noise
	  ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","Select",0)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:3]")

	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")
	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")
	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")

	  Sleep(500)
	  $handle=ControlGetHandle($MICPro, '', "[CLASS:SysListView32; INSTANCE:1]")

	  _GUICtrlListView_SetItemChecked($handle, 0, True);
	  Sleep(500)
	  _GUICtrlListView_SetItemChecked($handle, 1, False);
	  Sleep(500)
	  _GUICtrlListView_SetItemChecked($handle, 2, True);

	  Sleep(500)
	  ControlClick($MICPro,"","[CLASS:Button; INSTANCE:12]")
   Case 4:
	  ;setting for Microphone----noise and echo
	  ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","Select",0)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:3]")

	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")
	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")
	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")

	  Sleep(500)
	  $handle=ControlGetHandle($MICPro, '', "[CLASS:SysListView32; INSTANCE:1]")

	  _GUICtrlListView_SetItemChecked($handle, 0, True);
	  Sleep(500)
	  _GUICtrlListView_SetItemChecked($handle, 1, True);
	  ;;Sleep(500)
	  ;;_GUICtrlListView_SetItemChecked($handle, 2, True);

	  Sleep(500)
	  ControlClick($MICPro,"","[CLASS:Button; INSTANCE:12]")
   Case 5:
	  ;setting for Microphone----noise and echo
	  ControlListView($TitleRec, '', "[CLASS:SysListView32; INSTANCE:1]","Select",0)
	  ControlClick($TitleRec, '', "[CLASS:Button; INSTANCE:3]")

	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")
	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")
	  Sleep(500)
	  ControlCommand($MICPro,"", "[CLASS:SysTabControl32; INSTANCE:1]","TabRight")

	  Sleep(500)
	  $handle=ControlGetHandle($MICPro, '', "[CLASS:SysListView32; INSTANCE:1]")

	  _GUICtrlListView_SetItemChecked($handle, 0, True);
	  Sleep(500)
	  _GUICtrlListView_SetItemChecked($handle, 1, False);
	  Sleep(500)
	  _GUICtrlListView_SetItemChecked($handle, 2, True);

	  Sleep(500)
	  ControlClick($MICPro,"","[CLASS:Button; INSTANCE:12]")
EndSwitch

Sleep(500)
ControlClick($TitleRec,"","[CLASS:Button; INSTANCE:4]")
Exit(0)
